package gov.pbc.nn.core.datasource;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.pool.xa.DruidXADataSource;

public class CoreDruidDataSource extends DruidXADataSource implements
		InitializingBean {

	private static final long serialVersionUID = 1L;

	@Override
	public void init() throws SQLException {
//		String authenticationType = Configure
//				.getString("bdf2.authenticationType");
//		if (StringUtils.equalsIgnoreCase("cas", authenticationType)) {
//
//		} else {
//
//		}
		super.init();
	}

	private void initFilter() {
		List<Filter> filters = new ArrayList<Filter>();

		StatFilter stat = new StatFilter();
		filters.add(stat);

		Log4jFilter log = new Log4jFilter();
		log.setDataSourceLogEnabled(false);

		log.setResultSetLogEnabled(false);
		log.setResultSetLogErrorEnabled(false);

		log.setConnectionLogEnabled(false);
		log.setConnectionLogErrorEnabled(false);

		log.setStatementCreateAfterLogEnabled(false);
		log.setStatementCloseAfterLogEnabled(false);
		log.setStatementParameterClearLogEnable(false);
		log.setStatementPrepareAfterLogEnabled(false);
		log.setStatementExecuteQueryAfterLogEnabled(false);
		log.setStatementExecutableSqlLogEnable(false);
		filters.add(log);

		this.setProxyFilters(filters);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		this.initFilter();
	}
}
